#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

def fix_customer_detail():
    file_path = 'frontend/src/views/crm/components/CustomerDetailNew.vue'

    # 读取文件
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()

    # 修复客户来源字段的结束标签问题
    # 查找 <el-descriptions-item label="客户来源">{{ getSourceText(detail.source) || '-' }}
    # 替换为完整的标签
    pattern = r'<el-descriptions-item label="客户来源">\{\{ getSourceText\(detail\.source\) \|\| \'-\' \}\}</el-descriptions-item>'

    if not re.search(pattern, content):
        # 如果没有找到完整标签，说明缺少结束标签
        # 替换不完整的行
        incomplete_pattern = r'<el-descriptions-item label="客户来源">\{\{ getSourceText\(detail\.source\) \|\| \'-\' \}\}</el-descriptions-item>\s*\n'
        full_tag = '<el-descriptions-item label="客户来源">{{ getSourceText(detail.source) || \'-\' }}</el-descriptions-item>\n'
        content = re.sub(incomplete_pattern, full_tag, content)

    # 写入文件
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)

    print("✅ 标签修复完成！")

if __name__ == '__main__':
    fix_customer_detail()
